//
//  testViewController.m
//  phys
//
//  Created by iD Student on 7/13/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "testViewController.h"

@interface testViewController ()

@end

@implementation testViewController

- (void)viewDidLoad
{
    
    x=142;
    y=393;
    vx=2.0;
    vy=2.0;
    ax=0.03;
    ay=0.05;
    angle=45;
    speed=4;
    bounce=-1;
    gravity=0.1;
    
    
    ball = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ball.png"]];
    ball.frame=CGRectMake(50, 50, 32, 32);
    [self.view addSubview:ball];
    
    timer=[NSTimer scheduledTimerWithTimeInterval:0.005 target:self selector:@selector(animate) userInfo:nil repeats:YES];
    
    
    

    
    
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}


-(void) animate
{
    ball.center= CGPointMake(x, y);
    
    /*velocity*/
    x += vx;
    y += vy;
    
    /*gravity*/
    vy +=gravity;
    
    /*bounce*/
    if (x>304) {
        x=304;
        vx *= bounce;
    }
    else if(x < 20) 
    {
        x=20;
        vy *=bounce;
    }
    if (y>444) {
        y = 444;
        vy *= bounce;
    }
    else if (y<20)
    {
        y = 20;
        vy *= bounce;
    }
    
    
    /*Angular velocity*/
    //x+=cos(angle*M_PI / 180) *speed;
    //y+=sin(angle*M_PI / 180) *speed;
    
    /*accelration*/
    vx += ax;
    vy += ay;
    
    
}

@end
